package com.ruoyi.web.controller.youtobe;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.youtobe.domain.YoutobeVideoViewCount;
import com.ruoyi.youtobe.service.IYoutobeVideoViewCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Youtobe热播视频Controller
 *
 * @author ruoyi
 * @date 2025-11-16
 */
@RestController
@RequestMapping("/youtobe/count")
public class YoutobeVideoViewCountController extends BaseController {
    @Autowired
    private IYoutobeVideoViewCountService youtobeVideoViewCountService;

    /**
     * 查询Youtobe热播视频列表
     */
    @GetMapping("/list")
    public TableDataInfo list(YoutobeVideoViewCount youtobeVideoViewCount) {
        startPage();
        List<YoutobeVideoViewCount> list = youtobeVideoViewCountService.selectYoutobeVideoViewCountList(youtobeVideoViewCount);
        return getDataTable(list);
    }

    /**
     * 导出Youtobe热播视频列表
     */
    @Log(title = "Youtobe热播视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YoutobeVideoViewCount youtobeVideoViewCount) {
        List<YoutobeVideoViewCount> list = youtobeVideoViewCountService.selectYoutobeVideoViewCountList(youtobeVideoViewCount);
        ExcelUtil<YoutobeVideoViewCount> util = new ExcelUtil<YoutobeVideoViewCount>(YoutobeVideoViewCount.class);
        util.exportExcel(response, list, "Youtobe热播视频数据");
    }

    /**
     * 获取Youtobe热播视频详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(youtobeVideoViewCountService.selectYoutobeVideoViewCountById(id));
    }

    /**
     * 新增Youtobe热播视频
     */
    @Log(title = "Youtobe热播视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YoutobeVideoViewCount youtobeVideoViewCount) {
        return toAjax(youtobeVideoViewCountService.insertYoutobeVideoViewCount(youtobeVideoViewCount));
    }

    /**
     * 修改Youtobe热播视频
     */
    @Log(title = "Youtobe热播视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YoutobeVideoViewCount youtobeVideoViewCount) {
        return toAjax(youtobeVideoViewCountService.updateYoutobeVideoViewCount(youtobeVideoViewCount));
    }

    /**
     * 删除Youtobe热播视频
     */
    @Log(title = "Youtobe热播视频", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(youtobeVideoViewCountService.deleteYoutobeVideoViewCountByIds(ids));
    }
}
